#include "config_main.h"
#ifdef DDENN_INS_GARMIN_GTX_327
/*
 * ins_garmin_gtx_327.c
 *
 *  Created on: 06.06.2009
 *      Author: Admin
 */

#include "ins_garmin_gtx_327.h"

/**************************************************************************************/
//
//          it provides ddenn/instruments/garmin_gtx_327/
//
/*************************************************************************************/


DdennGarminGtx327::GarminGtx327RightFunction DdennGarminGtx327::RightFunction=altitude_fl;
int DdennGarminGtx327::_fake_numbers[9];

int DdennGarminGtx327::DDennGarminGtxPower=1;
int DdennGarminGtx327::TransponderCodeInputIndicator=1;
int DdennGarminGtx327::TransponderCode=7000;
int DdennGarminGtx327::TimerDownInputIndicator=0;
bool DdennGarminGtx327::TimerDownExpired=false;


void DdennGarminGtx327::RegisterDdennGarminGtx327(){
	XPLMRegisterDataAccessor( "ddenn/instruments/garmin_gtx_327/mode" ,    xplmType_Int, 1,
				GetInsGarminGtx327ButtonMode,SetGtxGarminGtx327ButtonMode,NULL,NULL,NULL, NULL,NULL,NULL,NULL,  NULL,NULL,    NULL,  NULL,NULL);
	XPLMRegisterDataAccessor( "ddenn/instruments/garmin_gtx_327/function" ,    xplmType_Int, 1,
			GetGtxGarminGtx327ButtonFunction,SetGtxGarminGtx327ButtonFunction,NULL,NULL,NULL, NULL,NULL,NULL,NULL,  NULL,NULL,    NULL,  NULL,NULL);

	XPLMRegisterDataAccessor( "ddenn/instruments/garmin_gtx_327/altitude_fl" ,    xplmType_Int, 0,
		                                   GetInsGarminGtx327Altitude_fl,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,  NULL,NULL,    NULL,  NULL,NULL);
	XPLMRegisterDataAccessor( "ddenn/instruments/garmin_gtx_327/altitude_meters" ,    xplmType_Int, 0,
		                                   GetInsGarminGtx327Altitude_meters,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,  NULL,NULL,    NULL,  NULL,NULL);
	XPLMRegisterDataAccessor( "ddenn/instruments/garmin_gtx_327/vertical_speed" ,    xplmType_Int, 0,
			                                   GetInsGarminGtx327Vertical_Speed,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,  NULL,NULL,    NULL,  NULL,NULL);
	XPLMRegisterDataAccessor( "ddenn/instruments/garmin_gtx_327/altitude_feets" ,    xplmType_Int, 0,
			                                   GetInsGarminGtx327Altitude_feets,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,  NULL,NULL,    NULL,  NULL,NULL);


	XPLMRegisterDataAccessor( "ddenn/instruments/garmin_gtx_327/transpoder_code" ,    xplmType_Int, 0,
			GetInsGarminGtx327TransponderCode,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,  NULL,NULL,    NULL,  NULL,NULL);
	XPLMRegisterDataAccessor( "ddenn/instruments/garmin_gtx_327/transpoder_code_input_indicator" ,    xplmType_Int, 0,
				GetInsGarminGtx327TransponderCodeInputIndicator,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,  NULL,NULL,    NULL,  NULL,NULL);

	XPLMRegisterDataAccessor( "ddenn/instruments/garmin_gtx_327/timer_down_hours" ,    xplmType_Int, 0,
			GetInsGarminGtx327TimerDownHours,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,  NULL,NULL,    NULL,  NULL,NULL);
	XPLMRegisterDataAccessor( "ddenn/instruments/garmin_gtx_327/timer_down_minutes" ,    xplmType_Int, 0,
				GetInsGarminGtx327TimerDownMinutes,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,  NULL,NULL,    NULL,  NULL,NULL);
	XPLMRegisterDataAccessor( "ddenn/instruments/garmin_gtx_327/timer_down_seconds" ,    xplmType_Int, 0,
					GetInsGarminGtx327TimerDownSeconds,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,  NULL,NULL,    NULL,  NULL,NULL);
	XPLMRegisterDataAccessor( "ddenn/instruments/garmin_gtx_327/timer_down_input_indicator" ,    xplmType_Int, 0,
			GetInsGarminGtx327TimerDownInputIndicator,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,  NULL,NULL,    NULL,  NULL,NULL);
	XPLMRegisterDataAccessor( "ddenn/instruments/garmin_gtx_327/timer_down_expired" ,    xplmType_Int, 0,
			GetInsGarminGtx327TimerDownExpired,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,  NULL,NULL,    NULL,  NULL,NULL);

	XPLMRegisterDataAccessor( "ddenn/instruments/garmin_gtx_327/timer_up_hours" ,    xplmType_Int, 0,
					GetInsGarminGtx327TimerUpHours,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,  NULL,NULL,    NULL,  NULL,NULL);
	XPLMRegisterDataAccessor( "ddenn/instruments/garmin_gtx_327/timer_up_minutes" ,    xplmType_Int, 0,
					GetInsGarminGtx327TimerUpMinutes,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,  NULL,NULL,    NULL,  NULL,NULL);
	XPLMRegisterDataAccessor( "ddenn/instruments/garmin_gtx_327/timer_up_seconds" ,    xplmType_Int, 0,
					GetInsGarminGtx327TimerUpSeconds,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,  NULL,NULL,    NULL,  NULL,NULL);

	XPLMRegisterDataAccessor( "ddenn/instruments/garmin_gtx_327/flighttime_hours" ,    xplmType_Int, 0,
					GetInsGarminGtx327FlightTimeHours,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,  NULL,NULL,    NULL,  NULL,NULL);
	XPLMRegisterDataAccessor( "ddenn/instruments/garmin_gtx_327/flighttime_minutes" ,    xplmType_Int, 0,
					GetInsGarminGtx327FlightTimeMinutes,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,  NULL,NULL,    NULL,  NULL,NULL);
	XPLMRegisterDataAccessor( "ddenn/instruments/garmin_gtx_327/flighttime_seconds" ,    xplmType_Int, 0,
					GetInsGarminGtx327FlightTimeSeconds,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,  NULL,NULL,    NULL,  NULL,NULL);

	XPLMRegisterDataAccessor( "ddenn/instruments/garmin_gtx_327/flighttime_raw" ,    xplmType_Float, 1,NULL,NULL,
						GetInsGarminGtx327FlightTimeRaw,SetInsGarminGtx327FlightTimeRaw,NULL, NULL,NULL,NULL,NULL,  NULL,NULL,    NULL,  NULL,NULL);


	for (int i=0; i<=(9); ++i){
	   	_fake_numbers[i]=i;
		/*XPLMRegisterCommandHandler(
				XPLMCreateCommand(commname,commdesc) ,
				  GarminGtx327ButtonNumber,1, &(_fake_numbers[i]));*/
    	XPLMRegisterDataAccessor( StPrintI("ddenn/instruments/garmin_gtx_327/button_number_%d", i) ,    xplmType_Int, 1,
    			ReturnDummyZero,GarminGtx327ButtonNumber,NULL,NULL,NULL, NULL,NULL,NULL,NULL,  NULL,NULL,    NULL,  NULL,&(_fake_numbers[i]));

	}

    XPLMRegisterDataAccessor( "ddenn/instruments/garmin_gtx_327/button_pause" ,    xplmType_Int, 1,
           			ReturnDummyZero,GarminGtx327ButtonPause,NULL,NULL,NULL, NULL,NULL,NULL,NULL,  NULL,NULL,    NULL,  NULL,NULL);


    XPLMRegisterDataAccessor( "ddenn/instruments/garmin_gtx_327/button_clr" ,    xplmType_Int, 1,
        			ReturnDummyZero,GarminGtx327ButtonCLR,NULL,NULL,NULL, NULL,NULL,NULL,NULL,  NULL,NULL,    NULL,  NULL,NULL);
    XPLMRegisterDataAccessor( "ddenn/instruments/garmin_gtx_327/button_crsr" ,    xplmType_Int, 1,
            			ReturnDummyZero,GarminGtx327ButtonCRSR,NULL,NULL,NULL, NULL,NULL,NULL,NULL,  NULL,NULL,    NULL,  NULL,NULL);

    TimerDownInputIndicator=0;
}

void DdennGarminGtx327::UnregisterDdennGarminGtx327(){


	XPLMUnregisterDataAccessor( XPLMFindDataRef( "ddenn/instruments/garmin_gtx_327/altitude_fl" ));
	XPLMUnregisterDataAccessor( XPLMFindDataRef( "ddenn/instruments/garmin_gtx_327/altitude_meters" ));
	XPLMUnregisterDataAccessor( XPLMFindDataRef( "ddenn/instruments/garmin_gtx_327/vertical_speed" ));
	XPLMUnregisterDataAccessor( XPLMFindDataRef( "ddenn/instruments/garmin_gtx_327/altitude_feets" ));
	XPLMUnregisterDataAccessor( XPLMFindDataRef( "ddenn/instruments/garmin_gtx_327/transpoder_code" ));
	XPLMUnregisterDataAccessor( XPLMFindDataRef( "ddenn/instruments/garmin_gtx_327/transpoder_code_input_indicator" ));
	XPLMUnregisterDataAccessor( XPLMFindDataRef( "ddenn/instruments/garmin_gtx_327/timer_down_hours" ));
	XPLMUnregisterDataAccessor( XPLMFindDataRef( "ddenn/instruments/garmin_gtx_327/timer_down_minutes" ));
	XPLMUnregisterDataAccessor( XPLMFindDataRef( "ddenn/instruments/garmin_gtx_327/timer_down_seconds" ));
	XPLMUnregisterDataAccessor( XPLMFindDataRef( "ddenn/instruments/garmin_gtx_327/timer_down_input_indicator" ));
	XPLMUnregisterDataAccessor( XPLMFindDataRef( "ddenn/instruments/garmin_gtx_327/timer_down_expired" ));


	XPLMUnregisterDataAccessor( XPLMFindDataRef( "ddenn/instruments/garmin_gtx_327/timer_up_hours" ));
	XPLMUnregisterDataAccessor( XPLMFindDataRef( "ddenn/instruments/garmin_gtx_327/timer_up_minutes" ));
	XPLMUnregisterDataAccessor( XPLMFindDataRef( "ddenn/instruments/garmin_gtx_327/timer_up_seconds" ));

	XPLMUnregisterDataAccessor( XPLMFindDataRef( "ddenn/instruments/garmin_gtx_327/flighttime_hours" ));
	XPLMUnregisterDataAccessor( XPLMFindDataRef( "ddenn/instruments/garmin_gtx_327/flighttime_minutes" ));
	XPLMUnregisterDataAccessor( XPLMFindDataRef( "ddenn/instruments/garmin_gtx_327/flighttime_seconds" ));
	XPLMUnregisterDataAccessor( XPLMFindDataRef( "ddenn/instruments/garmin_gtx_327/flighttime_raw" ));

	XPLMUnregisterDataAccessor( XPLMFindDataRef( "ddenn/instruments/garmin_gtx_327/mode" ));
	XPLMUnregisterDataAccessor( XPLMFindDataRef( "ddenn/instruments/garmin_gtx_327/function" ));

	for (int i=0; i<=(9); ++i){
    	_fake_numbers[i]=i;
    	XPLMUnregisterDataAccessor( XPLMFindDataRef(StPrintI("ddenn/instruments/garmin_gtx_327/button_number_%d", i)));
	}
	XPLMUnregisterDataAccessor( XPLMFindDataRef( "ddenn/instruments/garmin_gtx_327/button_pause"));

	XPLMUnregisterDataAccessor( XPLMFindDataRef( "ddenn/instruments/garmin_gtx_327/button_clr" ));

	XPLMUnregisterDataAccessor( XPLMFindDataRef( "ddenn/instruments/garmin_gtx_327/button_crsr" ));

}




bool DdennGarminGtx327::IsPowered(){
 return (DDennGarminGtxPower&&IsMainPowerOn(1));
}


int DdennGarminGtx327::ReturnDummyZero ( void *               inRefcon){
	return 0;
}


int DdennGarminGtx327::GetInsGarminGtx327Altitude_meters ( void *               inRefcon)
{

	return ((int)((GetDataRefF("sim/cockpit2/gauges/indicators/altitude_ft_pilot"))*0.3048));
}

int DdennGarminGtx327::GetInsGarminGtx327Altitude_feets ( void *               inRefcon){


	return ((int)((GetDataRefF("sim/cockpit2/gauges/indicators/altitude_ft_pilot"))));
}


int DdennGarminGtx327::GetInsGarminGtx327Altitude_fl ( void *               inRefcon)
{

	return ((int)((GetDataRefF("sim/cockpit2/gauges/indicators/altitude_ft_pilot"))/100));
}


int DdennGarminGtx327::GetInsGarminGtx327Vertical_Speed ( void *               inRefcon)
{
	float vs = (GetDataRefF("sim/cockpit2/gauges/indicators/vvi_fpm_pilot"));



	if (vs>(DDENNGARMINGTX327VERTICALSPEED_MAX)){
		return 2;
	}else{
		if (vs>(DDENNGARMINGTX327VERTICALSPEED_MININDICADED)){
			return 1;
		}else{
			if (vs<(-(DDENNGARMINGTX327VERTICALSPEED_MAX))){
				return -2;
			}else{
				if (vs<(-(DDENNGARMINGTX327VERTICALSPEED_MININDICADED))){
					return -1;
				}else {
					return 0;
				}
			}
		}
	}
}






int DdennGarminGtx327::GetInsGarminGtx327TransponderCodeInputIndicator ( void *               inRefcon){

return TransponderCodeInputIndicator;
}


int DdennGarminGtx327::GetInsGarminGtx327TimerDownInputIndicator ( void *               inRefcon){
return TimerDownInputIndicator;
}


int DdennGarminGtx327::GetInsGarminGtx327TimerDownExpired( void *               inRefcon){
	return (GetDataRefI(StPrintI("ddenn/timers_down/timer%d_expired", DDENNGARMINGTX327_USE_TIMER_COUNTDOWN_INDEX)));
}


int DdennGarminGtx327::GetInsGarminGtx327TimerDownHours ( void *               inRefcon){
	return (GetDataRefI(StPrintI("ddenn/timers_down/timer%d_hours", DDENNGARMINGTX327_USE_TIMER_COUNTDOWN_INDEX)));
}


int DdennGarminGtx327::GetInsGarminGtx327TimerDownMinutes ( void *               inRefcon){
	return (GetDataRefI(StPrintI( "ddenn/timers_down/timer%d_minutes", DDENNGARMINGTX327_USE_TIMER_COUNTDOWN_INDEX)));


}

int DdennGarminGtx327::GetInsGarminGtx327TimerDownSeconds ( void *               inRefcon){
	return (GetDataRefI(StPrintI("ddenn/timers_down/timer%d_seconds", DDENNGARMINGTX327_USE_TIMER_COUNTDOWN_INDEX)));
}


int DdennGarminGtx327::GetInsGarminGtx327TimerUpHours ( void *               inRefcon){
	return GetDataRefI(StPrintI("ddenn/timers/timer%d_hours", DDENNGARMINGTX327_USE_TIMER_COUNTUP_INDEX));
}


int DdennGarminGtx327::GetInsGarminGtx327TimerUpMinutes ( void *               inRefcon){
	return GetDataRefI(StPrintI("ddenn/timers/timer%d_minutes", DDENNGARMINGTX327_USE_TIMER_COUNTUP_INDEX));
}

int DdennGarminGtx327::GetInsGarminGtx327TimerUpSeconds ( void *               inRefcon){
	return GetDataRefI(StPrintI("ddenn/timers/timer%d_seconds", DDENNGARMINGTX327_USE_TIMER_COUNTUP_INDEX));
}



int DdennGarminGtx327::GetInsGarminGtx327FlightTimeHours ( void *               inRefcon){
	return GetDataRefI(StPrintI("ddenn/timers/timer%d_hours", DDENNGARMINGTX327_USE_TIMER_FLIGHTTIME_INDEX));
}


int DdennGarminGtx327::GetInsGarminGtx327FlightTimeMinutes ( void *               inRefcon){
	return GetDataRefI(StPrintI("ddenn/timers/timer%d_minutes", DDENNGARMINGTX327_USE_TIMER_FLIGHTTIME_INDEX));
}

int DdennGarminGtx327::GetInsGarminGtx327FlightTimeSeconds ( void *               inRefcon){
	return GetDataRefI(StPrintI("ddenn/timers/timer%d_seconds", DDENNGARMINGTX327_USE_TIMER_FLIGHTTIME_INDEX));
}


float DdennGarminGtx327::GetInsGarminGtx327FlightTimeRaw ( void *               inRefcon){
	return GetDataRefF(StPrintI("ddenn/timers/timer%d_raw", DDENNGARMINGTX327_USE_TIMER_FLIGHTTIME_INDEX));
}


void DdennGarminGtx327::SetInsGarminGtx327FlightTimeRaw ( void *               inRefcon, float inValue){
	SetDataRefF(StPrintI("ddenn/timers/timer%d_raw", DDENNGARMINGTX327_USE_TIMER_FLIGHTTIME_INDEX),inValue);
}





int DdennGarminGtx327::GetInsGarminGtx327TransponderCode ( void *               inRefcon){
	////////DDENNGARMINGTX327_AUTO_LAND_GEAR_FLIGHTTIME_PAUSE
	if (DDENNGARMINGTX327_AUTO_LAND_GEAR_FLIGHTTIME_PAUSE){
		if ((!GetDataRefFA("sim/flightmodel/parts/tire_vrt_def_veh",DDENNGARMINGTX327_AUTO_LAND_GEAR_FLIGHTTIME_PAUSE_USEGEARNUM))
				&&(GetDataRefI(StPrintI("ddenn/timers/timer%d_pause", DDENNGARMINGTX327_USE_TIMER_FLIGHTTIME_INDEX)))){
			SetDataRefI(StPrintI("ddenn/timers/timer%d_pause", DDENNGARMINGTX327_USE_TIMER_FLIGHTTIME_INDEX),1);
		}

		if ((GetDataRefFA("sim/flightmodel/parts/tire_vrt_def_veh",DDENNGARMINGTX327_AUTO_LAND_GEAR_FLIGHTTIME_PAUSE_USEGEARNUM))
				&&(!GetDataRefI(StPrintI("ddenn/timers/timer%d_pause", DDENNGARMINGTX327_USE_TIMER_FLIGHTTIME_INDEX)))){
			SetDataRefI(StPrintI("ddenn/timers/timer%d_pause", DDENNGARMINGTX327_USE_TIMER_FLIGHTTIME_INDEX),1);
		}
	}
	////////////////////////////
	return TransponderCode;
}



int DdennGarminGtx327::GetInsGarminGtx327ButtonMode ( void *               inRefcon){
	return GetDataRefI("sim/cockpit/radios/transponder_mode");
}

void DdennGarminGtx327::SetGtxGarminGtx327ButtonMode (void *   inRefcon,int  inValue){
	SetDataRefI("sim/cockpit/radios/transponder_mode",inValue);
	DDennGarminGtxPower=(inValue!=0);
}


int DdennGarminGtx327::GetGtxGarminGtx327ButtonFunction( void *               inRefcon){
	if (IsPowered()) return int(RightFunction); else return 0;
}

void DdennGarminGtx327::SetGtxGarminGtx327ButtonFunction (void *   inRefcon,int  inValue){
	if (IsPowered()){
		RightFunction=GarminGtx327RightFunction(inValue);
	}
}




void DdennGarminGtx327::GarminGtx327ButtonNumber (void *   inRefcon,int  inValue){
	if (inValue){
		if (IsPowered()){
			int *number = (int*)inRefcon;
			if (TransponderCodeInputIndicator)
			{
				TransponderCode=SetDigit(TransponderCode,(5-TransponderCodeInputIndicator),*number);
				TransponderCodeInputIndicator++;
				if (TransponderCodeInputIndicator<=4){
				}else {
					TransponderCodeInputIndicator=0;
					SetDataRefI("sim/cockpit/radios/transponder_code",TransponderCode);
				}
				//work with transpondercode
			}else{
				if ((RightFunction==count_down)&&(TimerDownInputIndicator)){
					//work with timer down
					switch (TimerDownInputIndicator){
				/*	case 1:
						sprintf(butnum, "ddenn/timers_down/timer%d_hours", DDENNGARMINGTX327_USE_TIMER_COUNTDOWN_INDEX);
						if ((SetDigit(GetDataRefI(butnum),2,*number))<=12) SetDataRefI(butnum,
								(SetDigit(GetDataRefI(butnum),2,*number)));
						break;
					case 2:
						sprintf(butnum, "ddenn/timers_down/timer%d_hours", DDENNGARMINGTX327_USE_TIMER_COUNTDOWN_INDEX);
						if ((SetDigit(GetDataRefI(butnum),1,*number))<=12) SetDataRefI(butnum,
								(SetDigit(GetDataRefI(butnum),1,*number)));
						break;*/
					case 1:
						if ((*number)<6) SetDataRefI(StPrintI("ddenn/timers_down/timer%d_minutes", DDENNGARMINGTX327_USE_TIMER_COUNTDOWN_INDEX),
								(SetDigit(GetDataRefI(StPrintI("ddenn/timers_down/timer%d_minutes", DDENNGARMINGTX327_USE_TIMER_COUNTDOWN_INDEX)),2,*number)));
						else TimerDownInputIndicator--;
						break;
					case 2:
						if ((*number)<10) SetDataRefI(StPrintI("ddenn/timers_down/timer%d_minutes", DDENNGARMINGTX327_USE_TIMER_COUNTDOWN_INDEX),
								(SetDigit(GetDataRefI(StPrintI("ddenn/timers_down/timer%d_minutes", DDENNGARMINGTX327_USE_TIMER_COUNTDOWN_INDEX)),1,*number)));
							else TimerDownInputIndicator--;
						break;
					case 3:
						if ((*number)<6) SetDataRefI(StPrintI("ddenn/timers_down/timer%d_seconds", DDENNGARMINGTX327_USE_TIMER_COUNTDOWN_INDEX),
								(SetDigit(GetDataRefI(StPrintI("ddenn/timers_down/timer%d_seconds", DDENNGARMINGTX327_USE_TIMER_COUNTDOWN_INDEX)),2,*number)));
							else TimerDownInputIndicator--;
						break;
					case 4:
						if ((*number)<10) SetDataRefI(StPrintI("ddenn/timers_down/timer%d_seconds", DDENNGARMINGTX327_USE_TIMER_COUNTDOWN_INDEX),
								(SetDigit(GetDataRefI(StPrintI("ddenn/timers_down/timer%d_seconds", DDENNGARMINGTX327_USE_TIMER_COUNTDOWN_INDEX)),1,*number)));
							else TimerDownInputIndicator--;
						break;
					}
					if (TimerDownInputIndicator>=4){
						TimerDownInputIndicator=0;
					}else{
						TimerDownInputIndicator++;
					}
				}
			}
		}
	}
}


void DdennGarminGtx327::GarminGtx327ButtonCLR(void *   inRefcon,int  inValue){
if (inValue){
if (IsPowered()){
 if (TransponderCodeInputIndicator){
	 TransponderCodeInputIndicator--;
 }else{


	if ((RightFunction==count_up)){
		//clear count up timer
		SetDataRefI(StPrintI("ddenn/timers/timer%d_clear", DDENNGARMINGTX327_USE_TIMER_COUNTUP_INDEX),1);
	}
	if ((RightFunction==flight_time)){
		//clear flighttime
		SetDataRefI(StPrintI("ddenn/timers/timer%d_clear", DDENNGARMINGTX327_USE_TIMER_FLIGHTTIME_INDEX),1);
	}
	if ((RightFunction==count_down)){
	    if (TimerDownInputIndicator){
	    	TimerDownInputIndicator--;
	    }else{
			SetDataRefI(StPrintI( "ddenn/timers_down/timer%d_pause", DDENNGARMINGTX327_USE_TIMER_COUNTDOWN_INDEX),1);
			SetDataRefI(StPrintI("ddenn/timers_down/timer%d_hours", DDENNGARMINGTX327_USE_TIMER_COUNTDOWN_INDEX),0);
			SetDataRefI(StPrintI("ddenn/timers_down/timer%d_minutes", DDENNGARMINGTX327_USE_TIMER_COUNTDOWN_INDEX),0);
			SetDataRefI(StPrintI("ddenn/timers_down/timer%d_seconds", DDENNGARMINGTX327_USE_TIMER_COUNTDOWN_INDEX),0);
	    }
	}
 }
}
}
}

void DdennGarminGtx327::GarminGtx327ButtonCRSR (void *   inRefcon,int  inValue){
if (IsPowered()&&inValue){
	/*if (!TransponderCodeInputIndicator){
		 TransponderCodeInputIndicator=1;
	 }else{
		 if ((RightFunction==count_down)&&(!TimerDownInputIndicator)){
			 TimerDownInputIndicator=1;
		 }
	 }*/
	TransponderCodeInputIndicator=(!TransponderCodeInputIndicator);

	TimerDownInputIndicator=(!TransponderCodeInputIndicator);


	if ((RightFunction==count_down)&&(TransponderCodeInputIndicator)&&(!GetDataRefI(StPrintI("ddenn/timers_down/timer%d_pause", DDENNGARMINGTX327_USE_TIMER_COUNTDOWN_INDEX)))) {
		SetDataRefI(StPrintI("ddenn/timers_down/timer%d_pause", DDENNGARMINGTX327_USE_TIMER_COUNTDOWN_INDEX),1);
		SetDataRefI(StPrintI("ddenn/timers_down/timer%d_hours", DDENNGARMINGTX327_USE_TIMER_COUNTDOWN_INDEX),0);
		SetDataRefI(StPrintI("ddenn/timers_down/timer%d_minutes", DDENNGARMINGTX327_USE_TIMER_COUNTDOWN_INDEX),0);
		SetDataRefI(StPrintI( "ddenn/timers_down/timer%d_seconds", DDENNGARMINGTX327_USE_TIMER_COUNTDOWN_INDEX),0);
	}
}
}


void DdennGarminGtx327::GarminGtx327ButtonPause (void *   inRefcon,int  inValue){
if (IsPowered()){
	if ((RightFunction==count_up)){
		//pause count up timer
		SetDataRefI(StPrintI("ddenn/timers/timer%d_pause", DDENNGARMINGTX327_USE_TIMER_COUNTUP_INDEX),1);
	}
	if ((RightFunction==flight_time)){
		//paues flighttime
		SetDataRefI(StPrintI("ddenn/timers/timer%d_pause", DDENNGARMINGTX327_USE_TIMER_FLIGHTTIME_INDEX),1);
	}
	if ((RightFunction==count_down)){
		//pause countdoun
		SetDataRefI(StPrintI("ddenn/timers_down/timer%d_pause", DDENNGARMINGTX327_USE_TIMER_COUNTDOWN_INDEX),1);
	}
}
}










/**************************************************************************************/
//
//          end of ddenn/instruments/garmin_gtx_327/
//
/*************************************************************************************/


#endif
